using System;
using System.Collections.Generic;
using System.Linq;
using FwkLight.CodeExtensions;

namespace FwkLight.Application.Caching
{
  public class BaseCacheDependencyConfig : ICacheDependencyConfig
  {
    private readonly IList<ITaskCacheDependency> _taskCacheDependencies;
    private Type _typeWaitingForCacheDefinition;

    public BaseCacheDependencyConfig(IList<ITaskCacheDependency> taskCacheDependencies)
    {
      _taskCacheDependencies = taskCacheDependencies;
    }

    protected BaseCacheDependencyConfig Task<T>() where T: IApplicationTask
    {
      _typeWaitingForCacheDefinition = typeof (T);
      return this;
    }

    public void ShouldResetCacheForTask<T>() where T: IApplicationTask
    {
      _taskCacheDependencies.Add(new TaskCacheDependency(_typeWaitingForCacheDefinition, typeof(T)));
    }

    public virtual void Configure()
    {
      
    }
  }
}